﻿Public Class frmCustomerAED
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        Me.StartPosition = FormStartPosition.CenterScreen
    End Sub
    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
    Public Sub LoadSex()
        cboSex.ValueMember = "sex_id"
        cboSex.DisplayMember = "sex"
        cboSex.DataSource = Cmd.ExecuteDataTable("select * from tblSex where Active = 1")
    End Sub

    Private Sub frmCustomerAED_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        LoadSex()
    End Sub

    Private Sub cboSex_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboSex.SelectedIndexChanged

    End Sub
    Public Sub Parameter()
        Cmd.Parameters("@Cus_code") = txtCus_Code.Text
        Cmd.Parameters("@Cus_Name") = txtCus_Name.Text
        Cmd.Parameters("@Sex") = cboSex.SelectedValue
        Cmd.Parameters("@Phone") = txtTel.Text
        Cmd.Parameters("@Email") = txtEmail.Text
        Cmd.Parameters("isaddress") = txtAdr.Text
    End Sub
    Private Sub btnEdite_Click(sender As Object, e As EventArgs) Handles btnEdite.Click
        If btnEdite.Text = "កែប្រែ" Then
            Cmd.Parameters("@Cus_Id") = txtId.Text
            Parameter()
            Cmd.ExecuteNonQuery("UPDATE tblCustomer SET Customer_Code = @Cus_Code, Customer_Name = @Cus_Name, Sex_id = @Sex, Phone = @Phone, Email = @Email, isaddress = @isaddress where customer_id = @Cus_Id")
            MsgBox("Insert Success...!")
            frmCustomerVeiwer.LoadData()
            Me.Close()
        Else
            Parameter()
            Cmd.ExecuteNonQuery("INSERT INTO tblCustomer VALUES (@Cus_Code, @Cus_Name, @Sex, @Phone, @Email,@isaddress ,1)")
            MsgBox("Insert Success...!")
            frmCustomerVeiwer.LoadData()
            Me.Close()
        End If
    End Sub
End Class